import java.util.Scanner;

public class Digits {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[][] arr = new int[n][n];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                arr[i][j] = input.nextInt();
        int count = Digits.digitCount(arr, n);
        System.out.println(count);
    }


    public static int digitCount(int[][] a, int n) {
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cnt += Count(a[i][j], n);

            }
        }

        return cnt;
    }
    public static int Count(int a, int n) {
        int ret = 0;
        while (a != 0) {
            if (n == a % 10) {
                ret++;
            }
            a /= 10;
        }
        return ret;
    }
}